package cn.microservices.cloud.common.core.annotation;


import cn.microservices.cloud.common.core.validator.EnumValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.*;

/**
 * 将此注解申明在属性上可以校验输入的参数值是否为指定的枚举值
 * 默认会取枚举中的code值与输入的参数值进行匹配
 */
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = {EnumValidator.class})
@Documented
public @interface EnumValid {

    String defMsg = "无效的枚举值";
    String defCodeValField = "getCode";


    String message() default defMsg;

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    Class<?>[] target() default {};

    String codeValFieldName() default defCodeValField;

}
